package bl.history;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;

import po.SystemLogPo;
import blservice.history.SystemLogBLService;
import vo.SystemLogVo;
import dbservice.history.SystemLogDBService;

public class SystemLogBL extends UnicastRemoteObject implements SystemLogBLService{

	private static final long serialVersionUID = 494375141039148603L;
	private SystemLogDBService db;
	
	public SystemLogBL(SystemLogDBService db)throws RemoteException{
		this.db=db;
	}

	public List<SystemLogVo> get() throws RemoteException{
		return P2V(db.get());
	}
	
	public List<SystemLogVo> get(SystemLogVo from,SystemLogVo to) throws RemoteException{
		return P2V(db.get(V2P(from), V2P(to)));
	}
	
	private List<SystemLogVo> P2V(List<SystemLogPo> po){
		List<SystemLogVo> result=new ArrayList<SystemLogVo>();
		for(SystemLogPo o:po){
			result.add(P2V(o));
		}
		return result;
	}
	
	private SystemLogVo P2V(SystemLogPo po){
		SystemLogVo vo=new SystemLogVo(po.getOperator(),po.getOperation(),po.getObject());
		vo.setDate(po.getDate());
		return vo;
	}
	
	private SystemLogPo V2P(SystemLogVo vo){
		SystemLogPo po=new SystemLogPo(vo.getOperator(), vo.getOperation(), vo.getObject());
		po.setDate(vo.getDate());
		return po;
	}
}
